package cz.muni.fi.hauntedhouses.util;

import cz.muni.fi.hauntedhouses.entity.House;
import cz.muni.fi.hauntedhouses.to.HouseTO;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author Jan Volmut, 324836
 */
public class HouseUtil {
    public static HouseTO toDTO(House house) {
        if (house == null) {
            return null;
        }
        
        HouseTO houseTO = new HouseTO();
        houseTO.setId(house.getId());
        houseTO.setAddress(house.getAddress());
        houseTO.setHauntedSince(house.getHauntedSince());
        houseTO.setHistory(house.getHistory());
        houseTO.setName(house.getName());
        
        return houseTO;
    }
    
    public static House toDAO(HouseTO houseTO) {
        if (houseTO == null) {
            return null;
        }
        
        House house = new House();
        house.setAddress(houseTO.getAddress());
        house.setHauntedSince(houseTO.getHauntedSince());
        house.setHistory(houseTO.getHistory());
        house.setId(houseTO.getId());
        house.setName(houseTO.getName());
        
        return house;
    }
    
    public static List<HouseTO> listToDTO(List<House> list) {
        List<HouseTO> result = new ArrayList<HouseTO>();
        Iterator<House> listIterator = list.iterator(); 
        while (listIterator.hasNext()) {
            result.add(HouseUtil.toDTO(listIterator.next()));
        }
        
        return result;
        
    }
}
